<?php
class PublicController extends Zendvn_Controller_Action{
	protected  $_arrParam;
	protected  $_currentController;
	protected  $_actionMain;
	
	public function init(){
		$this->_arrParam 			= $this->_request->getParams();
		
		$this->_currentController 	= '/'    . $this->_arrParam['module']
								     .'/'  . $this->_arrParam['controller'];
		
		$this->_actionMain 		   = '/'    . $this->_arrParam['module']
								     .'/'  . $this->_arrParam['controller']
								     .'/index';
		//Truyen ra ngoai view
		$this->view->arrParam 			= $this->_arrParam;
		$this->view->currentController 	= $this->_currentController;
		$this->view->actionMain  		= $this->_actionMain;
		//Khai bao template		
		$template_path = TEMPLATE_PATH . "/admin/system";
		$this->loadTemplate($template_path,'template.ini','public');
	}
	public function errorAction(){
		$this->view->Title = 'Message: Error!';
		$this->view->headTitle($this->view->Title,true);
		$error[] = 'Chuc nang nay khong ton tai !';
		$this->view->arrErrors = $error;
	}
	
	public function noAccessAction(){
		$this->view->Title = 'No Access !';
		$this->view->headTitle($this->view->Title,true);
		$error[] = 'Ban khong co quyen truy cap vao chuc nang nay !';
		$this->view->arrErrors = $error;
		
	}
	public function noAccessAclAction(){
		$template_path = TEMPLATE_PATH . "/admin/system";
		$this->loadTemplate($template_path,'template.ini','template');
		$this->view->Title = 'No Access !';
		$this->view->headTitle($this->view->Title,true);
		$error[] = 'Ban khong co quyen truy cap vao chuc nang nay !';
		$this->view->arrErrors = $error;
	}
	
	public function loginAction(){
		$this->view->Title = 'Login !';
		$this->view->headTitle($this->view->Title,true);
		
		if($this->_request->isPost()){
			$validator = new Default_Form_ValidateLogin($this->_arrParam);
			if($validator->isError() == true){
				$this->view->arrErrors = $validator->getMessageError();
				$this->view->Item	   = $validator->getData();
			}else{	
				$auth = new Zendvn_System_Auth();
				if($auth->login($this->_arrParam)){
					$info = new Zendvn_System_Info();
					$info->createInfo();
					$this->_redirect('/default/admin/index');
				}else{
					$error[]= $auth->getError();
					$this->view->arrErrors = $error;
				}
			}		
		}
	}
	public function logoutAction(){
		$this->view->Title = 'Logout !';
		$this->view->headTitle($this->view->Title,true);
		$auth = new Zendvn_System_Auth();
		$auth->logout();
		$info = new Zendvn_System_Info();
		$info->destroyInfo();
		$this->_redirect('/default/public/login');
		$this->_helper->viewRenderer->setNoRender();
		
	}
	
}













